package com.ruoyi.app.controller;

import com.ruoyi.cms.domain.CrmVisitor;
import com.ruoyi.cms.service.ICrmVisitorService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 访客预约Controller
 * 
 * @author hct
 * @date 2022-10-06
 */
@RestController
@RequestMapping("/app/visitor")
public class AppVisitorController extends BaseController
{
    @Autowired
    private ICrmVisitorService crmVisitorService;

    /**
     * 查询访客预约列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CrmVisitor crmVisitor)
    {
        startPage();
        List<CrmVisitor> list = crmVisitorService.selectCrmVisitorList(crmVisitor);
        return getDataTable(list);
    }



    /**
     * 获取访客预约详细信息
     */
    @GetMapping(value = "detail/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmVisitorService.selectCrmVisitorById(id));
    }

    /**
     * 新增访客预约
     */
    @PostMapping("apply")
    public AjaxResult apply( CrmVisitor crmVisitor)
    {
        int i=crmVisitorService.insertCrmVisitor(crmVisitor);
        if(i>0){
            return AjaxResult.success(crmVisitor);

        }else{
            return AjaxResult.error("异常");

        }
    }


    /**
     * 删除访客预约
     */
	@PostMapping("delete/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(crmVisitorService.deleteCrmVisitorById(id));
    }
}
